package com.superbytecode.cloud.web.transform;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: beacon-cloud
 * @Package: com.superbytecode.cloud.web.transform.aspect
 * @ClassName: TransformAspect
 * @Description: [转换器AOP]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/10/22 12:16
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Slf4j
@Aspect
@Component
@Order(2)
public class TransformAspect {
    @Resource
    private GenericConversionService genericConversionService;

    /**
     * 后置处理放啊
     *
     * @param responseValue 响应值
     */
    @AfterReturning(//
            pointcut = "@annotation(com.superbytecode.cloud.web.transform.annotation.Transform)",//
            returning = "responseValue"//
    )
    public void doAfter(Object responseValue) {
        // 获取容器中的转换器进行返回值解包，注意此处返回结果可能是Bean也可能是集合
        Object result = genericConversionService.convert(responseValue, Object.class);
        TransformUtil.transformObj(result);
    }
}